home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / c-lang / dbt.lha / DBT / DumpDB / dumpdb.c < prev    next >
C/C++ Source or Header  |  1996-05-03  |  2KB  |  85 lines

  1. //
  2. // DumpDB.c
  3. // Version 1.0
  4. // Dumps a DBTools database to the screen.
  5. //
  6. // ©1996 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // EMail: henriki@pluggnet.se
  10. //
  11.  
  12. #include <exec/types.h>
  13.  
  14. #include <utility/tagitem.h>
  15.  
  16. #include <proto/exec.h>
  17. #include <proto/dos.h>
  18.  
  19. #include "dbtools_pragmas.h"
  20. #include "dbtools.h"
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24.  
  25. char *ver="$VER: DumpDB 1.0";
  26.  
  27. struct Library *DBToolsBase;
  28.  
  29. main(int argc,char *argv[])
  30. {
  31.  DBase *db,*b;
  32.  DNode *n;
  33.  DData *d;
  34.  
  35.  if(argc!=2) {
  36.     printf("USAGE: %s <FILE>\n",argv[0]);
  37.     printf("DBTools ©1996 Henrik Isaksson\n");
  38.     printf("All Rights reserved.\n");
  39.     exit(0);
  40.  }
  41.  
  42.  DBToolsBase = OpenLibrary("dbtools.library",0);    // Any version will do this...
  43.  if(DBToolsBase) {
  44.     db=LoadBase(argv[1]);    // Load the base
  45.     if(db) {        // Is it loaded?
  46.         b=db;
  47.         while(b) {    // Scan through the bases
  48.             n=b->NList.First;
  49.             printf("BASE:\t");
  50.             while(n) {    // Scan through the nodes
  51.                 d=n->Data;
  52.                 printf("NODE:\t");
  53.                 while(d) {    // Print all data
  54.                     switch(d->Type) {
  55.                         case FTYPE_INT:
  56.                             printf("Integer: %ld (0x%08lx)\n",d->DInt.Int,d->DInt.Int);
  57.                             break;
  58.                         case FTYPE_STR:
  59.                             if(d->DStr.String) printf("String: \"%s\"\n",d->DStr.String);
  60.                             else printf("String: NULL\n");
  61.                             break;
  62.                         default:
  63.                             printf("Unknown data type\n");
  64.                     }
  65.                     d=d->Next;
  66.                     printf("\t\t");
  67.                 }
  68.                 printf("\n\t");
  69.                 n=n->Next;
  70.             }
  71.             printf("\n");
  72.             b=b->Next;
  73.         }
  74.  
  75.         printf("END\n");
  76.  
  77.         DeleteBase(db);    // We must always clean up when we exit...
  78.     } else {
  79.         printf("I can't find the file \"%s\"!\n",argv[1]);
  80.     }
  81.     CloseLibrary(DBToolsBase);
  82.  } else {
  83.     printf("I can't open \"dbtools.library\"!\n");
  84.  }
  85. }